#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
using namespace std;
typedef long long LL;
typedef double db;
inline int read()
{
	int x=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9') { if(ch=='-')f=-1; ch=getchar(); }
	while(ch>='0'&&ch<='9') { x=(x<<1)+(x<<3)+ch-'0'; ch=getchar(); }
	return x*f;
}
const int MAXN=1e4+10,MAXM=9e4+10;
int n,s,t,f[MAXM];
struct node
{
	int t1,t2,s;
	bool operator<(const node b)const
	{
		return t2==b.t2?t1<b.t1:t2<b.t2;
	}
}a[MAXN];
int main()
{
	n=read();s=read();t=read();
	memset(f,INF,sizeof(f));
	for(int i=1;i<=n;++i)a[i].t1=read(),a[i].t2=read(),a[i].s=read();
	sort(a+1,a+1+n);
	for(int i=1;i<=n;++i)
	{
		if(a[i].t1==s)
		{
			f[a[i].t2]=min(f[a[i].t2],a[i].s);
			continue;
		}
		for(int j=a[i].t1-1;j<a[i].t2;++j)
			f[a[i].t2]=min(f[a[i].t2],f[j]+a[i].s);
	}
	if(f[t]==INF)puts("-1");
	else printf("%d\n",f[t]);
	return 0;
}
